<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/base/taglibs.jsp"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>${systemOption.systemTitle}</title>
    <%@ include file="/base/head.jsp"%>
<script type="text/javascript">
$(document).ready(function(){
	//获取年度下拉框值
        var date = new Date(); 
        var year = date.getFullYear() - 2;
        for(var i = 0;i < 5 ; i++){
           if(year + i == date.getFullYear()){
             var option= $("<option></option>").val(year+i).text(year+i).attr("selected",true).appendTo($("#year"));
           }else{
             $("<option></option>").val(year+i).text(year+i).appendTo($("#year"));
           }
       	}
    });
    
   function getDate(){	
	var year=document.getElementById("year").value;	
	var year2=document.getElementById("year2");	
	year2.value=year;	
	var month=document.getElementById("month").value;	
	var month2=document.getElementById("month2");	
	month2.value=month;	
}
	//生成
	function add(){
		var year= $('#year').val();
		var month= $('#month').val();
		$.ajax({url:'${ctx}/attendence/addAttendence.action',
		data:{year:year,month:month},
		success:function(data){
			console.log(data);
			if(data == "01"){
				$.messager.alert('友情提示','当前月份的考勤信息生成成功','info');
			}else if(data == "02"){
				$.messager.alert('错误提示','当前月份的考勤信息生成失败','error');
			}else if(data == "03"){
				$.messager.alert('错误提示','当前月份的考勤信息已生成','error');
			}
			resetDG('#attendence');
		}
		});
	}
	
	//修改
  function edit(){
  	var row = $('#attendence').datagrid('getSelected');
	if (!row){
		$.messager.alert('友情提示','请选择信息','error');
	}else{
		$('#updateWnd').show();
		$('#updateWnd').dialog({
        iconCls:'icon-edit',
        title:'修改信息',
        modal:true,
        buttons:[{
				text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					$('#updateFrom').form('submit',{
					    success: function(data){
					        if(data=='01'){
					            $.messager.alert('友情提示','修改成功','info');
					            resetDG('#attendence');
					        }else{
					        	$.messager.alert('友情提示','修改失败','error');
					        }
					        $('#updateWnd').dialog('close');
					    }
					});
				}
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){
					$('#updateWnd').dialog('close');
				}
		}]
            });
 		$('#baseId').val(row.id);
 		$('#baseUId').val(row.uid);
 		$('#baseEmpId').val(row.aempid);
 		$('#baseAyear').val(row.ayear);
 		$('#baseAmonth').val(row.amonth);
 		$('#baseName').val(row.atruename);
 		$('#baseAlatecome').val(row.alatecome);
 		$('#baseAearlyleave').val(row.aearlyleave);
 		$('#baseAovertime').val(row.aovertime);
 		$('#baseAnegletwork').val(row.anegletwork);
 		$('#baseAleave').val(row.aleave);
		}
	}


	function export1(){
	var year=$('#year').val();
  	var month=$('#month').val();
	location.href= "${ctx}/attendence/export.action?year="+year+"&month="+month;
	}
 //分页查询
  function doQuery(){
  	var queryParams=$('#attendence').datagrid('options').queryParams;
  	queryParams.nameSch=$('#nameSch').val();
  	queryParams.empIdSch=$('#empIdSch').val();
  	queryParams.year=$('#year').val();
  	queryParams.month=$('#month').val();
  	
  	//重置当前页数为1
  	resetDG('#attendence');

  } 
  
  
  //选择一行顯示該課程的二維碼
    function show_tdewm(){
    	//顯示這門課程的二維碼
    		$('#kcewm').show();
    		$('#kcewm').dialog({
	 		title: '签到二维码', 	 		
		    cache: false, 
		    modal: true,
		    buttons:[{
		    	text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
					$('#kcewm').dialog('close');
				}	    	
		    }]
	 	});
	 		$('#ewmImg').attr('src','${ctx}/attendence/qdewm.action');
    
    }
</script>
</head>
<body>
	
	
	    <table id="attendence" class="easyui-datagrid" data-options="fit:true,
    								rownumbers:true,
									singleSelect:true,
									striped:true,
									fitColumns:true,
									toolbar:'#tb',
									pagination:true,
									pageSize:20,
									pageList:[20,30,50,100],
									url:'${ctx}/attendence/findAll.action'">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'aempid',align:'center',halign:'center'" width="120"><strong>工号</strong></th>
				<th data-options="field:'atruename',align:'center',halign:'center'" width="150"><strong>姓名</strong></th>
				<th data-options="field:'ayear',align:'center'" width="80"><strong>年份</strong></th>
				<th data-options="field:'amonth',align:'center'," width="80" ><strong>月份</strong></th>
				<th data-options="field:'alatecome',align:'center',halign:'center'" width="100"><strong>迟到次数</strong></th>
				<th data-options="field:'aearlyleave',align:'center',halign:'center'" width="100"><strong>早退次数</strong></th>
				<th data-options="field:'aovertime',align:'center',halign:'center'" width="100"><strong>加班时数</strong></th>
				<th data-options="field:'anegletwork',align:'center',halign:'center'" width="100"><strong>旷工时数</strong></th>
				<th data-options="field:'aleave',align:'center',halign:'center'," width="100"><strong>请假天数</strong></th>
				<th data-options="field:'uid',hidden:true"></th>
			</tr>
		</thead>
		
	</table>
<!-- Datagrid工具栏 -->
<div id="tb">
	<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
	   <td class="toolDiv">  	
	   <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-database-add',plain:true" onclick="add()">生成</a><span class="vline">|</span>	
	   <a href="javascript:void(0)" onclick="edit()" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a><span class="vline">|</span>	
	   <a href="javascript:void(0)" onclick="export1()" class="easyui-linkbutton" data-options="iconCls:'icon-printer',plain:true" >导出</a>
	   <a href="javascript:void(0)"	 class="easyui-linkbutton" data-options="iconCls:'icon-tip',plain:true" onclick="show_tdewm()">签到二维码</a>
		</td>
	</tr>
	<tr>
	   <td class="serchDiv">
			&nbsp;&nbsp;员工名称：<input id="nameSch"  class="easyui-textbox" type="text">
			&nbsp;&nbsp;员工工号：<input id="empIdSch"   class="easyui-textbox" type="text">
			&nbsp;&nbsp;年份：<select id="year" name="attendence.year" ></select>
			&nbsp;&nbsp;月份：	<select id="month" name="month">
				<c:forEach var="everyMonth" items="${monthList}"> 
	           		 <c:choose>
	           			  	<c:when test="${everyMonth==month}">
	           			  		<option  value="${everyMonth}" selected>${everyMonth}</option>
	           			  	</c:when>
	           			  	<c:otherwise>
	           			  		<option value="${everyMonth}">${everyMonth}</option>
	           			  	</c:otherwise>
	           			  </c:choose>
				</c:forEach>
			</select>
			&nbsp;&nbsp;<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doQuery()">查询</a>
			&nbsp;&nbsp;
			
		</td>
	</tr>
	</table>
</div>

	<!--修改窗口-->
    <div id="updateWnd"  style="width: 330px; height: 280px; padding: 5px; background: #fafafa;display: none">
    	<form id="updateFrom" method="post" action="${ctx }/attendence/updateAttendence.action">
    			<input id="baseId" name="id" type="hidden"/>
    			<input id="baseUId" name="uid" type="hidden"/>
    			<input id="baseEmpId" name="aempid" type="hidden"/>
    			<input id="baseAyear" name="ayear" type="hidden"/>
    			<input id="baseAmonth" name="amonth" type="hidden"/>
                <table cellpadding=3>
                	<tr>
                        <td>员工</td>
                        <td><input id="baseName" name="atruename"    readonly="readonly" style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>迟到次数 </td>
                        <td><input id="baseAlatecome" name="alatecome"    style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>早退次数</td>
                        <td><input id="baseAearlyleave" name="aearlyleave"    style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>加班时数</td>
                        <td><input id="baseAovertime" name="aovertime"    style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>旷工时数</td>
                        <td><input id="baseAnegletwork" name="anegletwork"    style="width:200px"/></td>
                    </tr>
                    <tr>
                        <td>请假天数</td>
                        <td><input id="baseAleave" name="aleave"  style="width:200px"/></td>
                    </tr>
                </table>
        </form>
    </div> 
</body>

	<div id="kcewm" style="display: none; width:400px;height:430px;background-color:white;border:false;">
		<!-- 二維碼圖片 -->
		<img  id="ewmImg"alt="簽到二維碼" src="" style="width:350px;height:350px;">
	</div>

</html>